package com.example.hhh.controller;

import com.example.hhh.model.Staff;
import com.example.hhh.service.StaffService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/staff")
public class StaffController {

    private final StaffService staffService;

    public StaffController(StaffService staffService) {
        this.staffService = staffService;
    }

    @PostMapping
    public ResponseEntity<Staff> createStaff(@RequestBody Staff staff) {
        return ResponseEntity.ok(staffService.createStaff(staff));
    }

    @GetMapping("/{id}")
    public ResponseEntity<Staff> getStaffById(@PathVariable Integer id) {
        return ResponseEntity.ok(staffService.getStaffById(id));
    }

    @PostMapping("/login")
    public ResponseEntity<Staff> login(
            @RequestParam String username,
            @RequestParam String password) {
        Staff staff = staffService.authenticate(username, password);
        return staff != null ?
                ResponseEntity.ok(staff) :
                ResponseEntity.status(401).build();
    }
}